﻿var thisWidget;
//当前页面业务
function initWidgetView(_thisWidget) {
    thisWidget = _thisWidget;
    if (thisWidget.config && thisWidget.config.style) {//适应不同样式
        $("body").addClass(thisWidget.config.style);
    }
    thisWidget.changePosition()
    // 是否显示框线
    $("#chkDebugFrustum").change(function () {
        if (thisWidget.selectedView == null) return;
        var debugFrustum = $(this).is(':checked');
        thisWidget.selectedView.debugFrustum = debugFrustum;
    });
    //调整 透明度
    $("#txtMixNum").range({
        onChange: function (value, bfb) {
            if (thisWidget.selectedView == null) return;
            thisWidget.selectedView.alpha = value;
        }
    });
    //水平拉伸
    $("#cameraFov").range({
        onChange: function (value, bfb) {
            if (thisWidget.selectedView == null) return;
            thisWidget.selectedView.fov = value;
        }
    });
    //相机宽高比例
    $("#cameraWidHei").range({
        onChange: function (value, bfb) {
            if (thisWidget.selectedView == null) return;
            thisWidget.selectedView.aspectRatio = value;
        }
    });
    //调整位置 相机
    $("#btnSelCamera").click(function () {
        thisWidget.seletCamera()
    });
    //鼠标图上点选 视点
    $("#btnSelView").click(function () {
        if (thisWidget.selectedView == null) return;
        thisWidget.drawType = "ViewPos";
        thisWidget.drawControl.clearDraw();
        thisWidget.drawControl.startDraw({ type: "point" });
    });
    //修改坐标 end
    $("#btnLocate").click(function () {
        if (thisWidget.selectedView == null) return;
        thisWidget.selectedView.locate();
    });
    // 打印参数
    $("#btnConsoleJson").click(function () {
        if (thisWidget.selectedView == null) return;
        var params = JSON.stringify(thisWidget.selectedView.params);
        console.log(params);
        haoutil.msg(params);
    });
    // 播放暂停按钮
    $("#btnPlayPause").click(function () {
        if (thisWidget.selectedView == null) return;
        thisWidget.selectedView.videoPlay = !thisWidget.selectedView.videoPlay;
    });
    bindKeydownEvnet()
}
//视频投放
function createViewForVideo() {
    //取屏幕中心点
    var debugFrustum = $("#chkDebugFrustum").is(':checked');
    var alpha = Number($("#txtMixNum").val());
    thisWidget.addVideoShed3D(debugFrustum,alpha)
}
//图片投放
function createViewForPicture() {
    var debugFrustum = $("#chkDebugFrustum").is(':checked');
    var alpha = Number($("#txtMixNum").val());
    thisWidget.addImageShed3D(debugFrustum,alpha)
}
// 文本投放
function createText(){
    var debugFrustum = $("#chkDebugFrustum").is(':checked');
    var alpha = Number($("#txtMixNum").val());
    thisWidget.addTextShed3D(debugFrustum,alpha)
}
//颜色投放
function createViewForColor() {
    //取屏幕中心点
    var debugFrustum = $("#chkDebugFrustum").is(':checked');
    var alpha = Number($("#txtMixNum").val());
    thisWidget.addColorShed3D(debugFrustum,alpha)
}
//清除
function clearVideo() {
    thisWidget.clearVideo();
}
//键盘微调控制
var cameraFollow = false;
var ratateDirection = {
    'LEFT': 'Z',
    'RIGHT': '-Z',
    'TOP': 'Y',
    'BOTTOM': '-Y',
    'ALONG': 'X',
    'INVERSE': '-X'
}
function bindKeydownEvnet() {
    $("#chkCameraFollow").change(function () {
        cameraFollow = $(this).is(':checked');
    });
    document.addEventListener('keydown', function (e) {
        switch (e.keyCode) {
            case 'A'.charCodeAt(0):
                rotateCamera(ratateDirection.LEFT);
                break;
            case 'D'.charCodeAt(0):
                rotateCamera(ratateDirection.RIGHT);
                break;
            case 'W'.charCodeAt(0):
                rotateCamera(ratateDirection.TOP);
                break;
            case 'S'.charCodeAt(0):
                rotateCamera(ratateDirection.BOTTOM);
                break;
            case 'Q'.charCodeAt(0)://Q键
                rotateCamera(ratateDirection.ALONG);
                break;
            case 'E'.charCodeAt(0)://E
                rotateCamera(ratateDirection.INVERSE);
                break;
        }
    }, false);
}
//微调视频 键盘微调
function rotateCamera(dir) {
    if (!thisWidget.selectedView) return;
    thisWidget.selectedView.rotateCamera(dir, $("#rotateDeg").val() * 1);
    thisWidget.cameraState(cameraFollow)
}

